package day04;

import java.util.Random;
import java.util.Scanner;

public class Guessin {
    public static void main(String[] args) {
        int sum = 1;//计数

        Random random = new Random();//生成一个随机数
        Scanner sc = new Scanner(System.in);

        //int num = random.nextInt(100);//100以内的随机数
        int num = (int) (Math.random() * 1000 + 1);


        while (true) {

            System.out.println("请您输入一个1000以内数");
            int guessin = sc.nextInt();

            if (guessin == num) {
                break;
            } else if (guessin < num) {
                System.out.println("猜小了");
                sum += 1;
            } else {
                System.out.println("猜大了");
                sum += 1;
            }
        }


       /* System.out.println("请您输入一个1000以内数");
        int guessin = sc.nextInt();

        while (num != guessin){
            if (guessin > num){
                System.out.println("猜大了");
            }

            else if(guessin < num){
                System.out.println("猜小了");
            }

            System.out.println("请重新输入");
            guessin = sc.nextInt();
            sum++;

        }*/
        System.out.println("恭喜你猜对了,一共猜了" + sum + "次");
    }

}
